package cn.gson.fengboot.model.service;

import cn.gson.fengboot.model.dao.DneedDao;
import cn.gson.fengboot.model.dao.DntemplateDao;
import cn.gson.fengboot.model.mapper.DneedMapper;
import cn.gson.fengboot.model.mapper.DntemplateMapper;
import cn.gson.fengboot.model.pojos.Dneed;
import cn.gson.fengboot.model.pojos.Dntemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class DneedService {
    @Autowired
    DntemplateMapper dntemplateMapper;

    @Autowired
    DneedMapper dneedMapper;

    @Autowired
    DneedDao dneedDao;

    @Autowired
    DntemplateDao dntemplateDao;


    public List<Dntemplate> selectAllnt(){
        return dntemplateMapper.selectAllnt();
    }

    public void addneed(Dneed dneed) {
        System.out.println(dneed.toString());
        if(dneed.getNtemplateId().getNtemplateNote()==""){
            dneed.setNtemplateId(null);
        }
        dneedDao.save(dneed);
    }

    public List<Dneed> selectAllnned(Integer busId) {
        return dneedMapper.selectAllnned(busId);
    }

    public void addntem(Dntemplate dntemplate) {
        dntemplateDao.save(dntemplate);
    }

    public void detntem(Integer ntemplateId) {
        dntemplateDao.deleteById(ntemplateId);
    }

    public Dneed selectById(Integer needId){
        return dneedDao.findById(needId).get();
    }

    public Integer selectByneedtheme(String needTheme, String getbuspeople) {
        List<Dneed> byNeedTheme = dneedDao.findByNeedTheme(needTheme, getbuspeople);
        if(byNeedTheme.size()>0){
            return 1;
        }else{
            return 0;
        }

    }
}
